import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: yinsh
 * Date: 2025-01-22
 * Time: 14:21
 */
public class MyQueue {
    Stack<Integer> stack1 = new Stack<>();
    Stack<Integer> stack2 = new Stack<>();

    public MyQueue() {

    }

    public void push(int x) {
        if (stack1.empty()&&stack2.empty()) {
            stack1.push(x);
        }else {
            stack1.push(x);
        }
    }

    public int pop() {
        int ret = 0;
        int size = 0;
        if (stack1.empty()&&stack2.empty()) {
            return -1;
        }else {
            if (!stack1.empty()) {
                size = stack1.size();
                for (int i = 0; i < size - 1; i++) {
                    stack2.push(stack1.pop());
                }
                ret = stack1.pop();
                size = stack2.size();
                for (int i = 0; i < size; i++) {
                    stack1.push(stack2.pop());
                }
            }
        }
        return ret;
    }

    public int peek() {
        int ret = 0;
        int size = 0;
        if (stack1.empty() && stack2.empty()) {
            return -1;
        } else {
            if (!stack1.empty()) {
                size = stack1.size();
                for (int i = 0; i < size; i++) {
                    stack2.push(stack1.pop());
                }
                ret = stack2.peek();
                size = stack2.size();
                for (int i = 0; i < size; i++) {
                    stack1.push(stack2.pop());
                }
            }
            return ret;
        }
    }

    public boolean empty() {
        if (stack1.empty()&&stack2.empty()) {
        return true;
    }
     return false;
    }
}
